<template>
  <div class="person">
    <h1>姓名：{{ name }}</h1>
    <h1>年龄：{{ age }}</h1>
    <button @click="changName">修改名字</button>
    <button @click="changAge">修改年龄</button>
    <button @click="showTel">查看联系方式</button>
  </div>
</template>

<script lang="ts">
export default {
  name: "person",
  data() {
    return {
      name: "张三",
      age: 18,
      tel: "18446846845",
    };
  },
  methods: {
    showTel(): void {
      // ts会报警告，因为在v2中写TS语法，this指向默认不包含隐式类型：any
      // 解决方法：(this as any) 断言，指定this就是any。或作在tsconfig.json中修改配置 【"strict": false】
      alert((this as any).tel);
    },
    changName(): void {
      this.name = "zhang-san";
    },
    changAge(): void {
      this.age += 1;
    },
  },
};
</script>

<style>
.person {
  background-color: turquoise;
  box-shadow: 0 0 10px;
  border-radius: 10px;
  padding: 20px;
}
button {
  margin: 0 5px;
}
</style>
